home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-24 | 4.1 KB | 137 lines | [TEXT/MPS ] |
- *
- * DriverGlue.a
- * Copyright © 1992, Apple Computer Inc., All Rights Reserved.
- *
- * This file contains the MPW driver header that will be used to
- * connect our device driver to the Macintosh O.S. Device Manager.
- * Note that it is a generic driver header file: you can use
- * this for any device driver.
- *
- * This must be the first module in the Link input specifier.
- *
- * Your driver must provide the following functions (globalized):
- *
- * OSErr OpenDRVR(
- * CntrlParam *paramBlock,
- * DCtlPtr devCtlEnt
- * );
- * OSErr CloseDRVR(
- * CntrlParam *paramBlock,
- * DCtlPtr devCtlEnt
- * );
- * OSErr PrimeDRVR(
- * CntrlParam *paramBlock,
- * DCtlPtr devCtlEnt
- * );
- * OSErr ControlDRVR(
- * CntrlParam *paramBlock,
- * DCtlPtr devCtlEnt
- * );
- * OSErr StatusDRVR(
- * CntrlParam *paramBlock,
- * DCtlPtr devCtlEnt
- * );
- *
- * This file is compiled by MPW and linked with the actual driver C
- * source files. It is not used when the driver is compiled by Think C.
- *
- * Author: Martin Minow
- * Apple Computer Inc.
- * Cupertino, CA, USA
- * InterNet: minow@apple.com
- * AppleLink: MINOW
- *
- print push,off ; Don't waste paper
- include 'SysEqu.a'
- include 'SysErr.a'
- include 'Traps.a'
- include 'DriverGlue.incl.a' ; MacsBug name macro
- print pop ; Restore print options
- case obj
- *
- * Define the external functions that DriverGlue must call.
- *
- DriverGlue proc export
- *
- * External definitions
- *
- import OpenDRVR
- import PrimeDRVR
- import ControlDRVR
- import StatusDRVR
- import CloseDRVR
- *
- * This module must be compiled as a 'DRVW' id=0 resource. Rez will
- * append this to the 'DRVR' resource that contains the driver header
- * data.
- *
- * The following is an interface between the Device Manager driver call
- * and the C function that performs the actual operation. It saves
- * registers, then builds a C parameter block that contains the
- * parameter block pointer and the driver control entry parameter
- * block pointer and calls the C function. Note that this driver
- * glue uses a standard C calling sequence. It might be slightly
- * more advantageous to use the pascal call sequence as the user
- * could write the handler function in either C or Pascal. However,
- * I also want to show how driver glue can be written using Think C
- * asm statements, so we're stuck with C glue. We build a complete
- * stack frame to simplify debugging trace backs.
- *
- * The driver glue handler performs three basic functions:
- * 1. It saves registers and builds a C parameter block on the stack.
- * 2. After the C handler returns, it test the immediate bit in
- * the trap word and returns directly if it was set.
- * 3. If the C function returns 1 (I/O in progress), it returns directly.
- * Otherwise, it the operation has completed, so the function exits
- * to the device manager via jIODone.
- *
- seg 'Main'
- export main
- main bra.s openGlue
- nop ; For DRVR offset
- bra.s primeGlue
- nop ; For DRVR offset
- bra.s controlGlue
- nop ; For DRVR offset
- bra.s statusGlue
- nop ; For DRVR offset
- closeGlue pea CloseDRVR
- bra.s common
- openGlue pea OpenDRVR
- bra.s common
- primeGlue pea PrimeDRVR
- bra.s common
- controlGlue pea ControlDRVR
- bra.s common
- statusGlue pea StatusDRVR
- * bra.s common
- *
- *
- common move.l (a7)+,d0 ; The function to call
- link a6,#0 ; Establish a stack frame
- movem.l d1-d3/a0-a4,-(a7) ; Save registers
- move.l a1,-(a7) ; Push DCE Ptr on the stack
- move.l a0,-(a7) ; Push ParamBlockPtr on the stack
- move.l d0,a0 ; Get the function to call
- jsr (a0) ; Call handler, result in d0
- addq.w #8,a7 ; Clear parameters from stack
- movem.l (a7)+,d1-d3/a0-a4 ; Restore registers
- btst #noQueueBit,ioTrap(a0) ; Is noQueueBit set?
- bne.s exit ; Branch if so
- cmp.w #1,d0 ; C result "incomplete"?
- beq.s exit ; Branch if so
- unlk a6 ; I/O complete, clear linkage
- move.l jIODone,-(a7) ; Return via jIODone
- rts ; Exit the driver glue
- *
- exit unlk a6 ; Destroy the linkage
- rts ; Exit to the caller
- DbgInfo DriverGlue
- endp
- *
- * That's all folks.
- *
- end
-
-
-